package cn.sylinx.common.ext.exception;

import cn.sylinx.common.ext.log.GLog;

public final class ExceptionCatcherUtil {

	public static boolean runWithCatch(Catcher exceptionCatcher) {
		return runWithCatch(exceptionCatcher, false);
	}

	public static boolean runWithCatch(Catcher exceptionCatcher, boolean printError) {
		return runWithCatchAndResult(exceptionCatcher, false, printError);
	}

	public static <T extends Object> T runWithCatchAndResult(GenericsCatcher<T> gc, T defaultValue,
			boolean printError) {

		try {
			return gc.run();
		} catch (Exception e) {
			if (printError) {
				GLog.error("run with catch exception :", e);
			}
		}

		return defaultValue;
	}
}
